﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml.Linq;

namespace WelcomeRESTXML
{
    public partial class WelcomeForm : Form
    {
        public WelcomeForm()
        {
            InitializeComponent();
        }

        private string port = "6806"; // put here your iis express port
        private HttpClient clinet = new HttpClient();

        private XNamespace stringNamespace = XNamespace.Get("http://schemas.microsoft.com/2003/10/Serialization/");

        private async void submitButton_Click(object sender, EventArgs e)
        {
            string result = await clinet.GetStringAsync(new Uri(string.Format("http://localhost:{0}/WelcomeService.svc/welcome/{1}", 
                port, nameTextBox.Text)));

            XDocument xmlResult = XDocument.Parse(result);

            MessageBox.Show(xmlResult.Element(stringNamespace + "string").Value, "Welcome", MessageBoxButtons.OKCancel,
                MessageBoxIcon.Exclamation);
        }
    }
}
